package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.mgb.model.Brand;
import com.macro.mall.mgb.model.Product;
import com.macro.mall.portal.domain.BrandDto;
import com.macro.mall.portal.domain.SimpleProductDTO;
import com.macro.mall.portal.service.PortalBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wangwang
 * @version 1.0
 * @description 首页品牌推荐管理
 * @date 2025/7/27 19:58
 */
@RestController
@RequestMapping("/brand")
@Tag(name = "HomeController", description = "首页品牌推荐管理接口")
public class PmsPortalBrandController {

    @Autowired
    private PortalBrandService portalBrandService;

    @Operation(summary = "分页获取推荐品牌")
    @RequestMapping(value = "/recommendList", method = RequestMethod.GET)
    public CommonResult<List<BrandDto>> recommendList(@RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<BrandDto> brandList = portalBrandService.recommendList(pageNum, pageSize);
        return CommonResult.success(brandList);
    }

    @Operation(summary = "获取品牌详情")
    @RequestMapping(value = "/detail/{brandId}", method = RequestMethod.GET)
    public CommonResult<Brand> detail(@PathVariable Long brandId) {
        Brand brand = portalBrandService.detail(brandId);
        return CommonResult.success(brand);
    }

    @Operation(summary = "分页获取品牌相关商品")
    @RequestMapping(value = "/productList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<SimpleProductDTO>> productList(@RequestParam Long brandId,
                                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        CommonPage<SimpleProductDTO> result = portalBrandService.productList(brandId,pageNum, pageSize);
        return CommonResult.success(result);
    }
}
